import java.util.Arrays;
import java.util.Scanner;

public class TestDay16 {

    //完全数
    public static void main1(String[] args) {
        //求约数
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int count = 0;
       for (int i = 2; i <=n ; i++) {
            if(func(i) == i){
                count++;
           }
        }
        System.out.println(count);
    }
    public static int func(int n){
        int sum = 0;
        for (int i = 2; i <=Math.sqrt(n) ; i++) {
            if(n % i == 0){
                sum += i;
                if(i * i != n){
                    sum += n / i;
                }
            }
        }
        return sum+1;
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        String[] array = str.split("-");
        String[] array1 = array[0].split(" ");
        String[] array2 = array[1].split(" ");
        String str1 = "34567891JQKA2";
        if(array[0] .equals("joker JOKER") || array[1] .equals("joker JOKER")){
            System.out.println("joker JOKER");
            return;
        }

        //注意J Q K A
        //如果牌数相等时
        if(array1.length == array2.length ){
            if(array1.length == 1){
                if(array1[0].equals("JOKER") || array2[0].equals("JOKER")){
                    System.out.println("JOKER");
                    return;
                }else if(array1[0].equals("joker") || array2[0].equals("joker")){
                    System.out.println("joker");
                    return;
                }
            }
            if (str1.indexOf(array1[0].substring(0,1)) > str1.indexOf(array2[0].substring(0,1))){
                System.out.println(array[0]);
            }else {
                System.out.println(array[1]);
            }
        }else {
            //如果牌数不相等时
            //如果有一个为4张牌时
            if(array1.length == 4){
                System.out.println(array[0]);
            }else if(array2.length == 4){
                System.out.println(array[1]);
            }else {
                System.out.println("ERROR");
            }
        }
    }

}
